import Link from "next/link";
import { notFound } from "next/navigation";
import { ArrowLeft } from "lucide-react";
import { requireAdmin } from "@/lib/session";
import { getOrganizationDetail } from "@/lib/queries/admin";
import { formatBytes, formatDate, formatMs, formatNumber, formatPercent, formatUsd } from "@/lib/format";
import { PageHeader } from "@/components/ui/page-header";
import { Badge, StatusBadge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Stat, StatGrid } from "@/components/ui/stat";
import { Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { CopyButton } from "@/components/ui/copy-button";
import { Alert } from "@/components/ui/alert";
import { DateCell, KV, MarginText, Mono, NetworkBadge, Panel, PlanBadge, numCell } from "@/components/admin/primitives";
import { OrgLimitsForm, OrgProviderVisibilitySwitch, OrgSuspendSwitch } from "@/components/admin/org-actions";
export const dynamic = "force-dynamic";
export default async function AdminOrganizationDetail({ params }: { params: Promise<{ id: string }> }) {
await requireAdmin();
const { id } = await params;
const d = await getOrganizationDetail(id);
if (!d) notFound();
const { org, stats30d: s } = d;
const margin = s.revenue - s.cost;
return (
<>
{org.name}
{org.suspended ? : null}
{org.providerVisibility ? provider debug on : null}
}
description={
{org.id}
· /{org.slug}
}
actions={
}
/>
{org.suspended ? API access is blocked for this organization. : null}
0 ? (margin / s.revenue) * 100 : null} />} />
Plan
Unlimited
private platform — plans are not configurable
{d.owner.email} : "—" },
{ label: "Stripe customer", value: org.stripeCustomerId ?? "not linked", mono: true },
{ label: "Created", value: formatDate(org.createdAt) },
{ label: "Updated", value: formatDate(org.updatedAt) },
]}
/>
User
Role
Joined
{d.members.map((m) => (
{m.email}
{m.name}
{m.role}
))}
Project
Env
Keys
Req 30d
Created
{d.projects.length === 0 ? (
No projects.
) : (
d.projects.map((p) => (
{p.name}
{p.archivedAt ? archived : null}
{p.id}
{p.environment}
{p.keys}
{formatNumber(p.requests30d)}
))
)}
Key
Project
Mode
Status
Last used
{d.keys.length === 0 ? (
No API keys.
) : (
d.keys.map((k) => (
{k.name}
{k.keyPrefix}…{k.last4}
{k.projectName ?? "—"}
{k.revokedAt ? : k.expiresAt && k.expiresAt < new Date() ? : }
))
)}
Request
Domain
Status
Network
Country
Latency
Cost
Price
When
{d.recentRequests.length === 0 ? (
No requests yet.
) : (
d.recentRequests.map((r) => (
{r.id}
{r.domain}
{r.errorCode ? {r.errorCode} : null}
{r.country ?? "—"}
{formatMs(r.latencyMs)}
{formatUsd(r.costUsd, true)}
{formatUsd(r.priceUsd, true)}
))
)}
When
Action
Target
Metadata
{d.audit.length === 0 ? (
No audit entries.
) : (
d.audit.map((a) => (
{a.action}
{a.target ?? "—"}
{a.metadata ? JSON.stringify(a.metadata) : "—"}
))
)}
>
);
}